﻿/* ==============================================================================
 * 功能描述：CharacterPanel  
 * 
 * 创 建 者：郑镇泉
 * 
 * 创建日期：2016/4/6 22:39:19
 * ==============================================================================*/
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using ZZQFrameWork;

public class CharacterMainPanel : BaseUI
{
    /// <summary>
    /// 关闭界面按钮
    /// </summary>
    private GameObject closeButton;

    private GameObject characterPanel;
    private GameObject skillPanel;

    private GameObject currentPanel;

    private GameObject characterPanelButton;
    private GameObject skillPanelButton;

    public override Enum_UIType GetUIType()
    {
        return Enum_UIType.CharacterMainPanel;
    }

    protected override void OnAwake()
    {
        closeButton = transform.Find("BG/CloseButton").gameObject;
        characterPanelButton = transform.Find("BG/CurrentTab/Character").gameObject;
        skillPanelButton = transform.Find("BG/CurrentTab/Skill").gameObject;
        characterPanel = transform.Find("BG/CharacterPanel").gameObject;
        skillPanel = transform.Find("BG/SkillPanel").gameObject;

        EventTriggerListener.Get(closeButton).SetEventHandle(Enum_TouchEventType.OnClick, OnCloseButtonClick);
        EventTriggerListener.Get(characterPanelButton).SetEventHandle(Enum_TouchEventType.OnClick, OnSwitchPanel);
        EventTriggerListener.Get(skillPanelButton).SetEventHandle(Enum_TouchEventType.OnClick, OnSwitchPanel);
    }

    void OnEnable()
    {
        OnSwitchPanel(characterPanelButton,null,null);
    }

    /// <summary>
    /// 切换界面
    /// </summary>
    /// <param name="_listener"></param>
    /// <param name="_args"></param>
    /// <param name="_params"></param>
    private void OnSwitchPanel(GameObject _listener, object _args, object[] _params)
    {
        Debug.Log("点击了切换界面按钮"+_listener.name);
        GameObject panel = null;
        switch (_listener.name)
        {
            case "Character":
                panel = characterPanel;break;
            case "Skill":
                panel = skillPanel;break;
        }
        if(currentPanel==panel)return;
        if(currentPanel!=null)currentPanel.SetActive(false);
        currentPanel = panel;
        currentPanel.SetActive(true);
    }

    private void OnCloseButtonClick(GameObject _listener, object _args, object[] _params)
    {
        //Debug.Log("点击了关闭按钮");
        UIManager.Instance.CloseUI(Enum_UIType.CharacterMainPanel);
    }

}